<?php
include_once 'category-order-list.php';
// Add RSS links to <head> section
add_theme_support('automatic-feed-links');

//Post thumbnail
add_theme_support('post-thumbnails');
set_post_thumbnail_size(100, 100, true);
add_image_size('sub-sumb', 93, 72, true);
add_image_size('last-news', 280, 188, true);
//Add post formats
add_theme_support('post-formats', array('gallery', 'image', 'video'));
// Load jQuery
if (!is_admin()) {
    //wp_deregister_script('jquery');
    //wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"), false);
    //wp_enqueue_script('jquery');
    wp_enqueue_script('hoverIntent', get_template_directory_uri() . '/js/hoverIntent.js', array('jquery'));
    wp_enqueue_script('superfish', get_template_directory_uri() . '/js/superfish.js', array('jquery'));
    wp_enqueue_script('cycle', get_template_directory_uri() . '/js/cycle.js', array('jquery'));
    wp_enqueue_script('jquery.anythingslider', get_template_directory_uri() . '/js/anythingslider.js', array('jquery'));
    wp_enqueue_script('custom', get_template_directory_uri() . '/js/custom.js', array('jquery'));
}

// Clean up the <head>
function removeHeadLinks() {
    remove_action('wp_head', 'rsd_link');
    remove_action('wp_head', 'wlwmanifest_link');
}

add_action('init', 'removeHeadLinks');
remove_action('wp_head', 'wp_generator');

add_action( 'init', 'create_post_type' );
function create_post_type() {
	register_post_type( 'members',
		array(
			'labels' => array(
				'name' => __( 'Members' ),
				'singular_name' => __( 'Member' )
			),
			'public' => true,
			'has_archive' => true,
			'rewrite' => array('slug' => 'members')
		)
	);
	
}

// Declare sidebar widget zone
if (function_exists('register_sidebar')) {
    register_sidebar(array(
        'name' => 'Sidebar Widgets',
        'id' => 'sidebar-widgets',
        'description' => 'These are widgets for the sidebar.',
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h2>',
        'after_title' => '</h2>'
    ));
     register_sidebar(array(
        'name' => 'New Magazine Cover',
        'id' => 'new-magazine-cover',
        'description' => 'The last new of Health Cambodia Magazine',
        'before_widget' => '<div>',
        'after_widget' => '</div>',
    ));
     
    register_sidebar(array(
        'name' => 'Related Post for Single Post Widgets',
        'id' => 'single-page-related-post',
        'description' => 'These are widgets for the sidebar.',
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h2>',
        'after_title' => '</h2>'
    ));
    register_sidebar(array(
        'name' => 'Home banner ads first place',
        'id' => 'home-ads-first-place',
        'description' => 'the Widget for home banner ads',
        'before_widget' => '<div>',
        'after_widget' => '</div>',
    ));
    register_sidebar(array(
        'name' => 'Home banner ads second place',
        'id' => 'home-ads-second-place',
        'description' => 'the Widget for home banner ads',
        'before_widget' => '<div>',
        'after_widget' => '</div>',
    ));
    register_sidebar(array(
        'name' => 'Home banner ads third place',
        'id' => 'home-ads-third-place',
        'description' => 'the Widget for home banner ads',
        'before_widget' => '<div>',
        'after_widget' => '</div>',
    ));
   //Right Sidebar ads
   register_sidebar(array(
        'name' => 'Right Sidebar Ads',
        'id' => 'right-sidebar-ads',
        'description' => 'The right sidebar ads at bottom',
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h3 class="widget-title">',
	'after_title' => '</h3>'
       
    ));
   //Right Sidebar ads
   register_sidebar(array(
        'name' => 'Left Sidebar Ads',
        'id' => 'ads-left-banner',
        'description' => 'The left sidebar ads at bottom',
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h3 class="widget-title">',
	'after_title' => '</h3>'
    ));
}

/**
 * Display simple posts
 * 
 * @param int $main_post_id
 */
function display_posts( $main_post_id) {
    $i = 1;
    while (have_posts()) : the_post();
    if ($main_post_id != get_the_ID() )
        if ( $i <= 2 ) {
        ?>

        <div <?php post_class() ?>>
            <div class="post-thumbnail">
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a>
            </div>
            <div class="post-content">
                <h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>

        <?php //include (TEMPLATEPATH . '/inc/meta.php' );  ?>

                <div class="entry">
                    <p>
        <?php echo get_the_excerpt(); ?>
                        ...(<a class="readmore" href="<?php the_permalink(); ?>">អាន​លម្អិត</a>)
                    </p>
                </div>
            </div>
            <div class="clearfix"></div>

        </div>

    <?php
        $i++;
        }
    endwhile;
}
/**
 * Display main articles
 * 
 */
function main_article() {
    //the_post();
    
?>
    <div id="last_news_cat">
                    <div class="photo">
                    <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('last-news'); ?></a>
                    </div>
                    <div class="last_topic">
                        <h3><a href="<?php the_permalink(); ?>"><?php the_title() ?></a></h3>
                        <div class="last_topic_summary">
                            <p>
                            <?php echo get_the_excerpt(); ?>
                                ...(<a href="<?php the_permalink(); ?>">អាន​លម្អិត</a>)
                            </p>
                        </div>
                        <span class="clearfix"></span>
                    </div>
                </div>
<?php 
    return get_the_ID();
}

function relatePostByCategory($cat_ID, $post_ID) {
    query_posts("cat=$cat_ID&posts_per_page=11");
    
    ?>
<ul class="related_post">
    <?php
        $i = 0;
        if (have_posts()) {
            while (have_posts()) : the_post();
            if ( $post_ID != get_the_ID()) {
                $i++;
                ?>
                    <li><a href="<?php the_permalink() ?>"><?php the_title() ?></a></li>
                <?php
                if ( $n == 10) 
                    break;
            }
            endwhile;
        }
    ?>
</ul>
    <?php
    wp_reset_query();
}

?>